/*
 * @Author: andy.dell andy@long.com
 * @Date: 2024-01-07 21:37:44
 * @LastEditors: andy.dell andy@long.com
 * @LastEditTime: 2024-01-07 21:37:44
 * @FilePath: \wasm\logic\snake\src\model\cell.go
 * @Description:
 */
package model

import (
	"com.game.snake/consts"
	"com.game.snake/utils"
)

type Cell struct {
	// Index       int // 位置/坐标
	Category    int // 分类：蛇、食物、障碍物
	SubCategory int // 子类型：不同食物、不同障碍物
}

func NewCell(category, subCategory int) *Cell {
	return &Cell{
		// Index:       index,
		Category:    category,
		SubCategory: subCategory,
	}
}

func NewSnakeBody() *Cell {
	return NewCell(consts.TypeBody, 0)
}
func NewFood(total int) *Cell {
	subCategory := utils.Rand(total)
	return NewCell(consts.TypeFood, subCategory)
}
func NewObstacle(total int) *Cell {
	subCategory := utils.Rand(total)
	return NewCell(consts.TypeObstacle, subCategory)
}

// 判断是蛇
func (c *Cell) IsSnake() bool {
	return c.Category == consts.TypeBody
}

// 判断是食物
func (c *Cell) IsFood() bool {
	return c.Category == consts.TypeFood
}

// 判断是障碍物
func (c *Cell) IsObstacle() bool {
	return c.Category == consts.TypeObstacle
}
